home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / sdf21.zip / SDF.ASM < prev    next >
Assembly Source File  |  1990-10-06  |  25KB  |  1,023 lines

  1. Title 'SDF : Speedy Disk Formatter'
  2.  
  3. ; **************************************************************************
  4. ; * THIS PROGRAM IS PUBLIC DOMAIN. You Are Free To Use It And Redistribute *
  5. ; * It, As Long As No Profit Is Made Out Of It. Redistribution Costs May   *
  6. ; * Not Exceed $5. This Notice May Not Be Removed Or Altered In Any Way.   *
  7. ; * Use At Your Own Risk. Author Will Not Be Held Responsible For Any Dama-*
  8. ; * ge That Might Result Of Use Or Misuse. Enjoy.               *
  9. ; **************************************************************************
  10.  
  11. ; This program is inspired from QDR by Vernon D. Buerg, which unfortunately
  12. ; has a bug in handling 3.5" floppies.
  13.  
  14. ; Better late than never, I dedicate this program to Ward Christensen, who
  15. ; showed us the way in the good old CP/M days ...
  16.  
  17. ; Jacques Pierson, Belgrade (Belgium), November 1987.
  18. ; CIS 76446,1516
  19.  
  20. ; Modification history:
  21. ; September 1990:  fixed bug with DMA boundary errors, and added code to turn
  22. ;    off the drive motor quickly.
  23. ; October 1990:  fixed bug in above bug fix.
  24.  
  25. M24    =    0    ;set to one at work, for an Olivetti M24 (ATT 6300) 
  26.  
  27. bell    equ    7
  28. bs    equ    8
  29. lf    equ    0Ah
  30. cr    equ    0Dh
  31. escape    equ    1Bh
  32. ulc    equ    0C9h    ;graphic char - Upper Left Corner
  33. llc    equ    0C8h    ;Lower Left Corner
  34. urc    equ    0BBh    ;Upper Right Corner
  35. lrc    equ    0BCh    ;Lower Right Corner
  36. vb    equ    0BAh    ;Vertical Border
  37. hb    equ    0CDh    ;Horizontal Border
  38. ;
  39. hsr    equ    0EFh    ;Head Step Rate : 4 ms
  40. hst    equ    0    ;Head Settle Time : 0 ms
  41. ;
  42.  
  43.  
  44. SDF    segment
  45.     assume ds:SDF, ss:SDF ,cs:SDF ,es:SDF
  46.  
  47.     org    0100h        ;make this a COM file
  48.  
  49.  
  50. start:    jmp    GetCmdLine
  51.  
  52. ; First describe our Disk Base Parms. We will make INT 1Eh to point here
  53. ; while formatting. Put at head of program so people without an assembler
  54. ; can easily patch this area w/ DEBUG.
  55.  
  56. OurDBP    equ    $
  57.  
  58.     db    hsr        ;high nibble : heads step rate
  59.                 ;low nibble, head unload time
  60.     db    2        ;DMA mode
  61.     db    255        ;clock ticks before stopping drive motor
  62.     db    2        ;sector size - 2 => 512 bytes
  63.     db    9        ;How many sectors per track
  64.     db    42        ;Gap length between sectors for R/W ops
  65.     db    -1        ;data length - Not used
  66.     db    80        ;Gap length when formatting
  67.     db    0F6h        ;Formatting char. Dos likes F6's
  68.     db    hst         ;Head settle time in ms.
  69.     db    1        ;Motor speed up time in 1/4 sec.
  70.  
  71. Welcome    db    cr,lf,'Speedy Disk Formatter, V1.0, '
  72.     db    '(c) Jacques Pierson, Nov 1987$'
  73.  
  74. UsageMessage    equ    $
  75.     db    cr,lf,lf,'Usage:  SDF drv: [switches]',cr,lf
  76.     db    'drv: mandatory and is either A: or B:,',cr,lf
  77.     db    'No switch => format standard 360K diskette, no verify',cr,lf
  78.     db    '/Q        => format Quad density (3',0abh,'" 720K disk)',cr,lf
  79.     db    '/V        => force Verify after format',cr,lf
  80.     db    'Multiple switches may be combined, e.g. SDF b:/q/v.'
  81.     db    cr,lf,lf,'$'
  82.  
  83. DriveMissing    db    cr,lf,lf,'Invalid or missing Drive Spec !$'
  84.  
  85. WrongSwitch    db    cr,lf,lf,'Unknown /switch in command line !$'
  86.  
  87. InsertDisk    db    cr,lf,lf,'Insert diskette in drive '
  88. Drive        db    'A, and press ENTER when ready ...$'
  89.  
  90. Again        db    cr,lf,lf,'Format complete,'
  91. Clusters    db    '      K available to user.'
  92.         db    cr,lf,'Press ENTER to format another diskette, '
  93.         db    'or ESCape to quit...$'
  94.  
  95. Formatting    db    cr,lf,lf,'Formatting '
  96. DiskType    db    'DSDD, Without$'
  97. Verify        db    ' Verify.',cr,lf,'$'
  98.  
  99. Track        db    cr,'Track: '
  100. TrackNr        db    '   Side: '
  101. SideNr        db    '   $'
  102.  
  103. ShowRetry    db    bs,'R$'
  104.  
  105. WritingBoot    db    ' - writing BOOT$'
  106. WritingFAT    db    ', FATs$'
  107. WritingDIR    db    ', DIR.$'
  108.  
  109. ErrorTbl    db    1,'Invalid command                '
  110.         db    2,'Address mark not found.        '
  111.         db    4,'Requested sector not found.    '
  112.         db    8,'DMA overrun on operation.      '
  113.         db    10h,'Bad CRC on diskette read/write.'
  114.         db    20h,'Controller failure.            '
  115.         db    40h,'SEEK operation failed.         '
  116. EndOfErrTbl    equ    $
  117.  
  118. FatalErr    db    bell,cr,lf,lf,'Door Open, Write-protected disk,'
  119.         db    ' or Drive Fails to respond.'
  120.         db    cr,lf,'Please fix problem and hit Enter to continue,'
  121.         db    'or ESCape to abort...$'
  122.  
  123. BadClusters    db    cr,lf,lf,'Bad sectors :'
  124. BadClNr        db    '       Cluster(s) disabled.',cr,lf,lf,'$'
  125. ;
  126. ErrBadSec    db    bs,bs,', Sec: '
  127. ErrSec        db    ' , Error '
  128. ErrCode        db    '   hex : '
  129. ErrMsg        db    'Unknown error.                 ',cr,lf,'$'
  130. ;
  131. ;
  132. ; Flags, set according to switches
  133. ;
  134. OptionsFlag    db    0    ;default is No Verify, Normal Disk
  135. CtrlBreak    db    0    ;Ctrl-Break flag on entry
  136. ;
  137. ; Disk characteristics, other parms are found in BootSector
  138. ;
  139. DirSecs        dw    7    ;DIRectory size in sectors
  140. DskTrks        db    40    ;Cyls/disk
  141. CurTrk        db    -1    ;Current track
  142. CurDrv        db    0    ;Current drive, binary, BIOS way (A:=0,..)
  143. NeedSetup    db    1    ;nonzero if default parms are in effect
  144.  
  145.     even            ;Align for those w/8086 processors
  146.  
  147. RetryCount    dw    0    ;Count of retries
  148. MaxTries    dw    2    ;Maximum retries attempted
  149. BadSecCnt    dw    0    ;Count of Bad Sectors
  150. NextSec        dw    0    ;Temp storage for next sector #
  151. INT1Eoff    dw    0    ;INT 1Eh offset
  152. INT1Eseg    dw    0    ;INT 1Eh segment
  153. INT24off    dw    0    ;Critical error handler offset
  154. INT24seg    dw    0    ;Critical error segment
  155. ;
  156. HexTbl        db    '0123456789abcdef'
  157. ;
  158. ID_tbl        dw    Side0    ;addr of table of ID's for track 0, side 0
  159.  
  160. Side0        db    0,0,1,2
  161.         db    0,0,2,2
  162.         db    0,0,3,2
  163.         db    0,0,4,2
  164.         db    0,0,5,2
  165.         db    0,0,6,2
  166.         db    0,0,7,2
  167.         db    0,0,8,2
  168.         db    0,0,9,2        ;end of side 0
  169.  
  170.         db    0,1,1,2        ;side 1 now
  171.         db    0,1,2,2
  172.         db    0,1,3,2
  173.         db    0,1,4,2
  174.         db    0,1,5,2
  175.         db    0,1,6,2
  176.         db    0,1,7,2
  177.         db    0,1,8,2
  178.         db    0,1,9,2        ;end of track, side 1
  179.  
  180. SideLen        equ    36
  181. ;
  182. ;
  183. ; Anatomy of our Boot sector
  184. ;
  185. BootSector    equ    $
  186.  
  187.         jmp    BootMsg
  188.  
  189.         db    'SDF  v01'    ;OEM name, 8 chars
  190.         dw    512        ;Sector size
  191.         db    2        ;Cluster size in sectors
  192.         dw    1        ;Reserved sectors
  193.         db    2        ;Number of FATs
  194. DirSize        dw    112        ;Directory entries
  195. TotSecs        dw    720        ;Total sectors
  196. MediaDes    db    0FDh        ;Media descriptor
  197. FatSize        dw    2        ;FAT size in sectors
  198.         dw    9        ;Sectors per Track
  199.         dw    2        ;Number of heads
  200.         dw    0        ;Number of hidden sectors
  201.         db    0        ;filler
  202.         db    0        ;head
  203.         db    10        ;length    of BIOS    file
  204.         db    hsr        ;The DPB, remember ?
  205.         db    2
  206.         db    25h
  207.         db    2
  208.         db    9
  209.         db    42
  210.         db    -1
  211.         db    80
  212.         db    0F6h
  213.         db    hst
  214.         db    1
  215.  
  216. NoBootMsg    equ    $
  217.  
  218.     db    cr,lf,lf
  219.     db    ulc,50 DUP (hb),urc,cr,lf
  220.     db    vb,'   This diskette has been formatted by SDF and    ',vb,cr,lf
  221.     db    vb,'    contains no system to boot from. Either       ',vb,cr,lf
  222.     db    vb,'  remove it and hit a key to boot from hard disk  ',vb,cr,lf
  223.     db    vb,'  if any, or replace it with another disk with a  ',vb,cr,lf
  224.     db    vb,'   system to boot from and hit a key when ready.  ',vb,cr,lf
  225.     db    llc,50 DUP (hb),lrc,cr,lf,lf,0
  226.  
  227.  
  228. BootMsg:
  229.     cli                ;no interrupts
  230.     cld                ;forward direction
  231.     mov    AX,07C0h        ;Boot runtime address
  232.     mov    DS,AX            ;to DS
  233.     mov    ES,AX
  234.     mov    SS,AX
  235.     mov    SP,0            ;temp stack at top of segment 
  236.     mov    SI,(OFFSET NoBootMsg - OFFSET BootSector) ;Msg ptr
  237. BNextChar:
  238.     lodsb                ;Get byte fm msg
  239.     or    AL,AL            ;a null ?
  240.     je    ReBoot            ;yes, print msg done
  241.     mov    AH,0Eh            ;print char, no bells and whistles
  242.     int    10h            ;Bios output char INT
  243.     jmp    SHORT BNextchar        ;loop for all string
  244. ;
  245. ReBoot:    xor    AH,AH            ;wait for key hit
  246.     int    16h
  247.  
  248.     int    19h            ;and try booting again 
  249.  
  250.  
  251. BEndOfStuff    equ    $
  252.  
  253.     db    (510 - (BEndOfStuff - BootSector)) DUP (0)    ;filler
  254.  
  255.     db    55h,0AAh        ;DOS disk signature
  256. ;
  257. ; End of boot sector
  258. ;
  259. ; First sector of File Allocation Table
  260. ;
  261. FatSec1    equ    $
  262.     db    0FDh            ;FAT - Media descriptor
  263.     db    0FFh
  264.     db    0FFh
  265.     db    509 DUP (0)        ;to get a full sector
  266.  
  267. FatSec2    db    512 DUP (0)        ;FAT, second sector
  268.     db    512 DUP (0)        ;FAT, third sector
  269. ;
  270. DirSec1    equ    $
  271. DskLbl    db    'SDF--------'        ;Dir entry for disk label, 11 char
  272.     db    28h            ;Attributes : Label + Archive
  273.     db    10 DUP (0)
  274. TimeLo    db    0
  275. TimeHi    db    0
  276. Date    dw    0
  277.     db    486 DUP (0)        ;full sector
  278. ;
  279. DirSec2    db    512 DUP (0)        ;2nd and other sectors
  280. ;
  281. ;
  282. ; Control-Break handler : DO NOT give user a chance to exit w/^C or Break
  283. ; without resetting the environement...
  284. ;
  285. ControlBreak: 
  286.  
  287.     iret                ;trap ^C and simply return
  288. ;
  289. ;
  290. ; Critical Error handler:  Same as above.  Note that, contrary to documentation
  291. ; (under DOS 2.1 at least), selecting 'a' under Abort/Retry/Fail does not put
  292. ; you into INT 23.
  293. ;
  294. CritError:
  295.     push    AX
  296.     push    DX
  297.     push    DS
  298.     push    CS
  299.     pop    DS
  300.     call    Restore
  301.     pop    DS
  302.     pop    DX
  303.     pop    AX
  304.     jmp    far cs:[IN